package com.wsoft.hr.pm.manager.sys;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wsoft.constant.redis.HrPmRedisKeyConstant;
import com.wsoft.constant.redis.RedisKeyConstant;
import com.wsoft.core.annotation.GetRedisCache;
import com.wsoft.core.utils.SqlAuthDisableHolder;
import com.wsoft.entity.BaseEntity;
import com.wsoft.hr.pm.entity.sys.HrOrganizationEntity;
import com.wsoft.hr.pm.mapper.HrOrganizationMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Zhang gukai
 * @Date 2025/2/18 15:03
 */
@Service
public class HrOrganizationManager extends ServiceImpl<HrOrganizationMapper, HrOrganizationEntity> {

    public List<HrOrganizationEntity> getOrgByCode(Long id, String code) {
        QueryWrapper<HrOrganizationEntity> query = new QueryWrapper<>();
        if (id != null) {
            query.lambda().ne(BaseEntity::getId, id)
                    .eq(HrOrganizationEntity::getCode, code);
        } else {
            query.lambda().eq(HrOrganizationEntity::getCode, code);
        }
        return list(query);
    }

    public List<HrOrganizationEntity> getOrgByPaId(Long paId) {
        QueryWrapper<HrOrganizationEntity> query = new QueryWrapper<>();
        query.lambda().eq(HrOrganizationEntity::getPaId, paId);
        return list(query);
    }
    @GetRedisCache(type = HrPmRedisKeyConstant.HR_ALL_ORG,
            value = RedisKeyConstant.REDIS_NULL)
    public List<HrOrganizationEntity> listAllHrOrgWithCache() {
        SqlAuthDisableHolder.open();
        List<HrOrganizationEntity> list = list();
        SqlAuthDisableHolder.close();
        return list;
    }
}
